package cn.fx.framework.exception;

import cn.fx.framework.cons.ErrorCodeMessage;
import cn.fx.framework.core.CodeMessage;

/**
 * 业务类异常
 * @author ljh
 * @date 2018-08-16 9:10
 */
public class ServiceException extends BaseException {
    public ServiceException(int code, String msg){
        super(code, msg);
    }

    public ServiceException(CodeMessage codeMessage){
        this(codeMessage.getCode(), codeMessage.getMessage());
    }

    public ServiceException(String msg){
        this(ErrorCodeMessage.SERVICE_EXCEPTION_MSG.getCode(), msg +
                "@{" + ErrorCodeMessage.SERVICE_EXCEPTION_MSG.getMessage() + "}");
    }

    @Override
    public String toString() {
        String ret = "";
        if(this.code>0){
            ret = "异常代码："+code+"，错误信息：";
        }
        ret += this.getMessage();
        return ret;
    }
}
